<?php
// +----------------------------------------------------------------------
// | 奇乐中介担保交易系统 免费版 2019
// +----------------------------------------------------------------------
// | 官方网址：http://www.qilecms.com   
// +----------------------------------------------------------------------
// | 产品文档：http://www.qilecms.com/doc
// +----------------------------------------------------------------------
// | 开发作者:奇乐CMS
// +----------------------------------------------------------------------
// | 版权说明：这不是一个自由软件！本产品仅限个人使用，但请务必保留底部版权，以免产生不必要的纠纷,
// | 您只能在不用于商业目的的前提下对程序代码进行修改和使用，
// | 任何企业和个人不允许对程序代码以任何形式任何目的再发布。
// +----------------------------------------------------------------------
namespace app\guarantee\controller;
class Search  extends Base
{
    public function index()
    {
      $param = $this->request->param();
      $keywords = !empty($param['keywords'])?$param['keywords']:'';
      $price    = !empty($param['p'])?$param['p']:''; //价格
      $cid      = !empty($param['c'])?$param['c']:''; //分类
      $status   = !empty($param['s'])?$param['s']:''; //状态
      $id_type   = !empty($param['i'])?$param['i']:''; //发布者身份
      $order_price  = !empty($param['op'])?$param['op']:'';
      if(!empty($keywords)){
       $where[] =['title','like',"%$keywords%"] ;

      }
      //分类
       if(!empty($cid)){
         $where[] =['cid','=',$cid];   
       }
      // 价格
       if(!empty($price)){
       	switch($price)
       	{
       		case 1:
       		 $where[] =['price','<','1000'];
       		break;
       		case 2:
             $where[] =['price','between',['1000','5000']];
       		break;
       		case 3:
              $where[] =['price','between',['5000','10000']];
       		break;
	        case 4:
              $where[] =['price','between',['10000','50000']];
       		break;
	        case 5:
              $where[] =['price','between',['50000','100000']];
       		break;
	        case 6:
              $where[] =['price','between',['100000','200000']];
       		break;
	        case 7:
              $where[] =['price','>','200000'];
       		break;
       	}        
      }
    //交易状态
    if(!empty($status)){
         $where[] =['status','=',$status];   
       }


  //排序
      if($order_price ==1){
        $order_price =2;
        $order['price'] ='asc';  //价格从小到大
      }elseif($order_price ==2){
        $order_price =1;
        $order['price'] ='desc';  //价格从大到小
      }else{
        $order_price =1;

      }

      $order['create_time'] ='desc';  //价格从大到小
      $this->assign('order_price',$order_price);


      $cate = $this->getCache('guaranteeCategory','cid');
      $this->assign('guaranteecategory',$cate);
  //审核状态
     $where[] =['status','in',[1,2,3]];  //已审核 已交易 交易完成 

     $urlParam['keywords'] = $keywords;
     $urlParam['p'] = $price;
     $urlParam['s'] = $status;
     $urlParam['c'] = $cid;
     $urlParam['i'] = $id_type;
     $urlParam['op'] = $order_price;
     $list =  model('guaranteeInfo')->listPageData($where,'*',$order,'10,false,$urlParam');
    
     foreach($list as $k=>$v){
         	$where1['cid'] = $v['cid'];
         	$where1['status'] = 1;
         	$list[$k]['cname'] = $cate[$v['cid']]['cname'];
     }

     
   
     $page = $list->render();
     $this->assign('page',$page);
     
     $category = $this->getCache('guaranteeCategory','cid');
    
     $this->assign('cate',$category[$cid]);
 

  

     $empty = '<div class="empty">暂时没有数据</div>';
     $this->assign('empty',$empty);
     $this->assign('list',$list);
     return $this->fetch();
    }

}